package me.nickpierson.SpringIdol.Main;

import me.nickpierson.SpringIdol.POJOS.Performer;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("spring-idol.xml");

		String[] performers = { "duke", "kenny", "richie", "hank", "tommy", "carl", "nick" };
		run(getPerformers(context, performers));

		((ClassPathXmlApplicationContext) context).close();
	}

	public static Performer[] getPerformers(ApplicationContext context, String... ids) {
		Performer[] performers = new Performer[ids.length];
		for (int i = 0; i < ids.length; i++) {
			performers[i] = (Performer) context.getBean(ids[i]);
		}

		return performers;
	}

	public static void run(Performer... performers) {
		for (Performer performer : performers) {
			System.out.println("\nNext up: ");
			performer.perform();
		}
	}
}